import {request} from "@/api/service";

export const crudOptions = {
  options: {
    // height: null,
    // maxHeight: null
    height: '100%',
    fetchDetail (index, row, mode) {
      console.log(index, row, mode)
      return row
    }
  },
  pageOptions: {
    compact: true // 是否紧凑型页面
  },
  searchOptions: {
    show: false
  },
  formOptions: {
    defaultSpan: 12
  },
  pagination: {
    pageSizes: [10, 20]
  },
  columns: [
    {
      title: 'ID',
      key: 'id',
      width: 90,
      form: {
        disabled: true
      }
    },
    {
      title: '项目',
      key: 'project',
      show: true,
      search: {
        disabled: true
      },
      type: 'select',
      dict: {
        cache: true,
        url: '/api/config/project/?limit=999',
        value: 'id', // 数据字典中value字段的属性名
        label: 'name', // 数据字典中label字段的属性名
        getData: (url) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            return ret.data.data
          })
        }
      },
      form: {
        component: {
          name: 'dict-select',
          props: {
            elProps: {
              // size: 'medium',
              clearable: true,
              showAllLevels: false, // 仅显示最后一级
              props: {
                checkStrictly: true, // 可以不需要选到最后一级
                emitPath: false,
                clearable: true
              }
            }
          }
        },
        valueChange (key, value, form, { mode, getColumn, component, immediate, getComponent }) {
          if (value) {
            form.name = undefined// 将county的value置空
            const moduleSelect = getComponent('id')
            if (form && form.project) {
              console.log(11111111111111)
              moduleSelect.reloadDict() // 重新加载字典项
            } else {
              console.log(3333333333333333)
              moduleSelect.clearDict() // 清空选项
            }
          }
        }
      }
    },
    {
      title: '模块',
      key: 'id',
      sortable: true,
      search: { disabled: false },
      type: 'select',
      dict: {
        value: 'name',
        url (dict, { form, component }) {
          if (form.project != null) {
            console.log(3333)
            return '/api/devops/module/?limit=999&project=' + form.project
          }
          console.log(444444)
          return undefined
        }
      },
      form: {
        component: { props: { dict: { cache: false } } },
        valueChange (key, value) {
          console.log('您选择了：', value)
        }
      }
    }
  ]
}
